<template>
	<view>
		<view class="seed" v-if="bind_data.superior.type=='seed'">
			您是尊贵的种子用户！
		</view>
		<view class="" v-if="bind_data.superior.people!==undefined && bind_data.superior.people.length !==0">
			<view class="tit">邀请人</view>
			<view class="lists">
				<view class="list">
					<image :src="bind_data.superior.people.avatar" class="tou"></image>
					<view class="msg">
						<view class="">
							{{bind_data.superior.people.nickname}}
						</view>
						<view class="">
							邀请时间: {{bind_data.superior.people.join_time}}
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="">
			<view class="tit">
				<view>我的粉丝 ({{bind_data.subordinate.people!==undefined ? bind_data.subordinate.people.length: 0 }} 人)</view>
				<view class="select_box">
					<view class="uni-list-cell-db">
					    <picker @change="bindPickerChange" :value="index" :range="array1">
					          <view class="uni-input">{{array1[index]}}</view>
					    </picker>
					</view> 
					<image src="../../static/images/show-more.png" class="more"></image>
				</view>
			</view>
			<view class="lists" v-if="!no_data">
				<view class="list" v-for="(item,key) in bind_data.subordinate.people" :key="key">
					<image :src="item.avatar" class="tou"></image>
					<view class="msg">
						<view class="">
							{{item.nickname}}
						</view>
						<view class="">
							邀请时间: {{item.join_time}}
						</view>
					</view>
				</view>
				
			</view>
			<view class="show_no_data" v-if="no_data">
				暂无粉丝，快去分享商城给朋友吧~
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				array: [{
					name:'关联时间',
					start_time:'',
					end_time:'',
				}],
				array1: ['关联时间'],
				index: 0,
				user_id: 0,
				bind_data:{},
				no_data:false
			}
		},
		onShow() {
			var self = this;
			let date = new Date();
			let day28 = [];
			let day29 = [];
			let day30 = [4,6,9,11];
			let day31 = [1,3,5,7,8,10,12];
			let year = date.getFullYear();
			if(year%4==0&&year%100!=0||year%400==0){
			       day29 = [2]
			　　}else{
			　　   day28 = [2]
			　　}
			
			let month = parseInt(date.getMonth())+1;
			for(let i = 1; i<7;i++){
				let obj={};
				let _time = '' + year +'-' + (month<10 ? '0'+month : month);
				obj.name = _time;
				obj.start_time = _time+'-01 23:59:59';
				obj.end_time = '';
				
				if(day28.indexOf(month)!==-1){
					obj.end_time = _time+'-28 23:59:59';
					console.log(28)
				}else
				if(day29.indexOf(month)!==-1){
					obj.end_time = _time+'-29 23:59:59';
					console.log(29)
				}else
				if(day30.indexOf(month)!==-1){
					obj.end_time = _time+'-30 23:59:59';
					console.log(30)
				}else
				if(day31.indexOf(month)!==-1){
					obj.end_time = _time+'-31 23:59:59';
					console.log(31)
				}
				self.array.push(obj);
				self.array1.push(_time);
				month--;
				year = month>0 ? year : year-1;
				month = month>0 ? month : 12;
			}
			console.log(self.array)
			self.$request.request({
				url:'/user/info',
				success:function(res){
					self.stauts_code = res.code
						if(res.code == 200){
							self.user_id = res.result.id;
							self.getBind();
						}
				}
			});
		},
		methods: {
			bindPickerChange: function(e) {
			     console.log('picker发送选择改变，携带值为', e.target.value)
			     this.index = e.target.value;
				 this.getBind()
			},
			getBind(){
				var self = this;
				console.log({
						p:1,
						per:100000,
						user_id:self.user_id,
						begin_time:self.array[self.index].start_time,
						end_time:self.array[self.index].end_time
					})
					uni.showLoading({
					    title: '加载中'
					});
				self.$request.request({
					url:'/user/get_bind',
					data:{
						p:1,
						per:100000,
						user_id:self.user_id,
						begin_time:self.array[self.index].start_time,
						end_time:self.array[self.index].end_time
					},
					success:function(res){
						self.stauts_code = res.code
							uni.hideLoading();
							if(res.code == 200){
								console.log(res.result)
								self.bind_data = res.result;
								if(self.bind_data.subordinate.people!==undefined){
									self.no_data = false
								}else{
									self.no_data = true
								}
							}
					}
				});
			}
		}
	}
</script>

<style scoped>
.lists{
	width: 750upx;
}
.tit{
	display: flex;
	flex-direction: row;
	justify-content: space-between;
	box-sizing: border-box;
	font-size: 14px;
	padding: 20upx 20upx 0 20upx;
}
.seed{
	padding: 20upx;
	font-size: 16px;
}
.select_box{
	position: relative;
	width: 150upx;
	overflow: hidden;
	border: 1px solid #e1e1e1;
	padding: 3upx;
	font-size: 12px;
	padding-left:10upx;
	border-radius: 5upx;
}
.uni-input {
	height: auto;
	padding: 0;
}

.list{
	box-sizing: border-box;
	display: flex;
	flex-direction: row;
	justify-content: flex-start;
	padding: 20upx;
	font-size: 12px;
	border-bottom: 1px solid #f0f0f0;
}
.tou{
	width: 80upx;
	height: 80upx;
	border-radius: 100%;
	margin-right: 20upx;
}
.msg{
	display: flex;
	flex-direction: column;
	justify-content: space-between;
}
.more{
	position: absolute;
	width: 12upx;
	height: 10upx;
	right: 10upx;
	top:20upx
}
.show_no_data{
	width: 750upx;
	margin-top: 40upx;
	text-align: center;
}
</style>
